﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using XueMeng.BLL;
using XueMeng.Model;
using System.Text.RegularExpressions;

namespace UI
{
    public partial class EmpEdit : Form
    {
        public EmpEdit()
        {
            InitializeComponent();
        }

        private void EmpEdit_Load(object sender, EventArgs e)
        {
            LoadData();
            LoadEvent();
        }

        private void LoadData()
        {
            LoadPost();
        }

        private void LoadPost()
        {
            PostManager pm = new PostManager();
            this.comboBox1.DataSource = pm.GetModelList("");
            this.comboBox1.DisplayMember = "P_Name";
            this.comboBox1.ValueMember = "P_Id";
        }

        private void LoadEvent()
        {
            this.button1.Click += new EventHandler(button1_Click);
        }

        void button1_Click(object sender, EventArgs e)
        {
            SaveEmp();
        }

        private void SaveEmp()
        {
            EmployeeManager em = new EmployeeManager();
            if (String.IsNullOrEmpty(this.textBox1.Text.Trim()))
            {
                MessageBox.Show("请输入姓名","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
            Employee emp = new Employee()
            {
                E_Name = this.textBox1.Text.Trim(),
                P_Id = Convert.ToInt32(this.comboBox1.SelectedValue),
                Cam_Id = 0,
                Enable = 0
            };

            if (em.Add(emp)>0)
            {
                MessageBox.Show("保存成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("保存失败");
            }

        }
    }
}
